#include "BuiltInFunc.h"

#include <assert.h>
#include <math.h>

const BuiltInFunc::FuncName BuiltInFunc::sNameMap[BuiltInFunc::sFuncNum] = 
{
    { "SIN", sin },
    { "COS", cos },
    { "TAN", tan },
    { "ATN", atan },
    { "EXP", exp },
    { "ABS", fabs },
    { "LOG", log },
    { "SQR", sqrt },
    { "INT", TruncToInt },
    { "RND", Random }
};

float BuiltInFunc::Eval( std::string name, float arg )
{
    for (int i = 0; i < sFuncNum; i++)
    {
        if (sNameMap[i].name == name)
        {
            return sNameMap[i].pFunc(arg);
        }
    }
    assert(0);
    return -1;
}

bool BuiltInFunc::IsMember( std:: string name )
{
    for (int i = 0; i < sFuncNum; i++)
    {
        if (sNameMap[i].name == name)
        {
            return true;
        }
    }
    return false;
}

float BuiltInFunc::TruncToInt( float arg )
{
    return (float)(int)arg;
}

float BuiltInFunc::Random( float arg )
{
    return rand() * (1.0 / RAND_MAX);
}




